import collections


class Solution(object):

    def __init__(self, nums):
        """
        :type nums: List[int]
        """
        self.d = collections.defaultdict(set)
        for index, item in enumerate(nums):
            self.d[item].add(index)

    def pick(self, target):
        """
        :type target: int
        :rtype: int
        """
        index = self.d[target].pop()
        self.d[target].add(index)
        return index


data = Solution()
